package com.ft.javaio.nio;

import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @Author RenPu
 * @Date 2023/7/18 10:40
 * @Version 1.0
 * @Description:  模拟向文件写入数据，通过buffer
 **/
public class Channel_001 {

    public static void main(String[] args) throws Exception {
        // 构造一个传统的文件输出流
        FileOutputStream out = new FileOutputStream(
                "C:\\Users\\12795\\Desktop\\hello.txt");
        // 通过文件输出流获取到对应的FileChannel，以NIO的方式来写文件
        FileChannel channel = out.getChannel();

        ByteBuffer buffer = ByteBuffer.wrap("welcome to new life happiness !!!!".getBytes());
        channel.write(buffer);

        channel.close();
        out.close();
    }

}


